package com.czu.service.impl;

import com.ctc.wstx.util.StringUtil;
import com.czu.service.RegistService;
import com.taotao.mapper.TbUserMapper;
import com.taotao.pojo.TbUser;
import com.taotao.pojo.TbUserExample;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.DigestUtils;
import org.springframework.util.StringUtils;

import java.util.Date;

@Component
public class RegistServiceImpl implements RegistService {

    @Autowired
    private TbUserMapper mapper;

    @Override
    public boolean regist(String username, String password) {
        try {
            if(StringUtils.isEmpty(username)||StringUtils.isEmpty(password))
            {
                return false;
            }
            TbUser user = new TbUser();
            user.setUsername(username);
            user.setPassword(DigestUtils.md5DigestAsHex(password.getBytes()));
            user.setCreated(new Date());
            user.setUpdated(new Date());
            mapper.insert(user);
        }
        catch (Exception e)
        {
            e.printStackTrace();
            return false;
        }
        return true;
    }
}
